package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.LoginSet;
import com.prs.crm.service.sys.LoginSetService;

public class LoginSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private LoginSet loginSet;
	private LoginSetService loginSetService;
	private String serCode;

	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public LoginSet getLoginSet() {
		return loginSet;
	}
	public void setLoginSet(LoginSet loginSet) {
		this.loginSet = loginSet;
	}
	public LoginSetService getLoginSetService() {
		return loginSetService;
	}
	public void setLoginSetService(LoginSetService loginSetService) {
		this.loginSetService = loginSetService;
	}
	
	@Action("editLoginSet")
	public String editLoginSet(){
		this.loginSet=this.getLoginSetService().getLoginSet(serCode);
		return SUCCESS;
	}
	@Action(value="saveLoginSet",results={
			@Result(name="success",type="redirect",location="editLoginSet?serCode=${loginSet.getType()}"),
			@Result(name="error",type="chain",location="editLoginSet?serCode=${loginSet.getType()")
	})
	public String saveLoginSet(){
		LoginSet login=this.getLoginSetService().getLoginSet("ls01");
		if(login==null){
			login=new LoginSet();
			login.setType("ls01");
			login.setSoleId(loginSet.getSoleId());
			login.setUrl(loginSet.getUrl());
			login.setUseUSBKEY(loginSet.getUseUSBKEY());
			login.setWindowMax(loginSet.getWindowMax());
			login.setRemark(loginSet.getRemark());
			login.setBirthDayWarn(loginSet.getBirthDayWarn());
			login.setGraphChecking(loginSet.getGraphChecking());
			this.getLoginSetService().save(login);
		}else{
			this.getLoginSetService().submit(login);
		}
		loginSet=login;
		return SUCCESS;
	}
	@Action(value="saveLoginSets",results={
			@Result(name="success",type="redirect",location="editLoginSet?loginSet=${loginSet.getId()}"),
			@Result(name="error",type="chain",location="editLoginSet?loginSet=${loginSet.getId()")
	})
	public String saveLoginSets(){
		this.getLoginSetService().save(loginSet);
		return SUCCESS;
	}
}
